package com.heima.lock.sjms.原型模式;

/**
 * @author 陈辉
 * @data 2024 15:04
 */

class  Cls implements Cloneable{

    @Override
    protected Cls clone() throws CloneNotSupportedException {
        return (Cls) super.clone();
    }

    private String cname;

    @Override
    public String toString() {
        return "Cls{" +
                "cname='" + cname + '\'' +
                '}';
    }

    public String getCname() {
        return cname;
    }

    public void setCname(String cname) {
        this.cname = cname;
    }
}

public class Student implements Cloneable{
    private String name;
    private int age;
    private Cls cls;

    @Override
    protected Student clone() throws CloneNotSupportedException {
        Student stu = (Student) super.clone();
        Cls cls = stu.getCls().clone();
        stu.setCls(cls);
        return stu;
    }

    @Override
    public String toString() {
        return "Student{" +
                "name='" + name + '\'' +
                ", age=" + age +
                ", cls=" + cls +
                '}';
    }

    public Cls getCls() {
        return cls;
    }

    public void setCls(Cls cls) {
        this.cls = cls;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }
}
